from urllib.request import Request, urlopen
from urllib.parse import urlencode

req = Request('https://httpbin.org/get', headers={'User-Agent': 'Edge/134.0.3124.51'})
response = urlopen(req)
html = response.read().decode('utf-8')
print("Get请求发送：", response.status)
print("响应数据：\n", html)

login_data = urlencode({"username": "test_user", "password": "123456"}).encode('utf-8')
req = Request(url='https://httpbin.org/post', data=login_data, method='POST')
response = urlopen(req)
print("POST送达：", response.status)
print("响应头：", response.getheaders())
print(response.read().decode('utf-8'))